﻿using System;
using System.Collections.Generic;
using System.Linq;
using Go.Tools;
using System.Threading;

namespace Go.Model
{
    public class HumanPlayer: Player
    {
        private static Position actualMove;
        private static Boolean actualMoveIsSetted;
        public HumanPlayer(Color aColor, String name): base(aColor, name)
        {
            resetActualMove();
        }

        public static HumanPlayer WhitePlayer(String name)
        {
            return new HumanPlayer(Color.White, name);
        }

        public static HumanPlayer BlackPlayer(String name)
        {
            return new HumanPlayer(Color.Black, name);
        }

        public override void play() {
            NotifyObservers(this);
            base.play();
            while (!actualMoveIsSetted) {
                Thread.Sleep(ConstantThread.SleepTime);
            }
            putStone(actualMove);
            resetActualMove();
        }

        private void resetActualMove() {
            actualMove = null;
            actualMoveIsSetted = false;
        }

        public override String playerType() { return "Humano"; } 

        public override Boolean isHumanPlayer() { return true; }

        public override void setMove(Position aPosition)
        {
            actualMove = aPosition;
            actualMoveIsSetted = true;
        }
    }
}
